import RegexInput from '@/utils/RegexInput'

export const elevator = {
  data() {
    return {
      START_ROW_NUM: 3,
      errInfoArray: []
    }
  },
  methods: {
    getErrInfo(i, j, info, type) {
      let s = ''
      if (type === 0) { s = '第' + i + '行,' + '第' + j + '列，存在错误！只能为:' + info }
      if (type === 1) { s = '第' + i + '行,' + '第' + j + '列，存在错误！格式不正确:' + info }
      if (type === 2) { s = '第' + i + '行,' + '存在错误！关联数据不正确:' + info }
      return s
    },
    checkField(rowIndex, colIndex, value) {
      switch (colIndex) {
        case 1 : {
          if (RegexInput.regCode(value) === false) {
            this.errInfoArray.push(this.getErrInfo(rowIndex, colIndex, value, 1))
          }
          break
        }
        case 2 : {
          if (RegexInput.safeCode(value) === false) {
            this.errInfoArray.push(this.getErrInfo(rowIndex, colIndex, value, 1))
          }
          break
        }
      }
    },
    check(rowIndex, colIndex, value) {
      this.checkField(rowIndex, colIndex, value)
    },
    getInfoArray() {
      return this.errInfoArray
    }
  }
}

export default elevator
